package com.jeff.springWebTestNG.persistence.ibatis.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.MappedTypes;
import org.springframework.stereotype.Service;

import com.jeff.springWebTestNG.persistence.data.User1;

/**
 * This persister use new style @ annotation to define sql script
 * @author zhou.zhefu
 *
 */
@Service
//@MappedTypes(User1.class)
public interface IUserMapper {
	@Select("SELECT * FROM user_1 WHERE id = #{userId}")
	User1 getUserById(@Param("id") int id);
	
	@Select("SELECT * FROM user_1 WHERE name = #{userName}")
	List<User1> getUserByName(@Param("userName") String userName);
	
	@Insert("INSERT INTO user_1 (name, age) values (#{userName}, #{age})")
	int createUser(@Param("userName") String userName, @Param("age") int age);
	
	@Insert("INSERT INTO user_1 (name, age) values (#{name}, #{age})")
	int createUser_1(@Param("user") User1 user);//cannot same name reload with the above "createUser()"
	
	@Update("UPDATE user_1 SET name = #{user.name}, age = #{user.age} WHERE id = #{user.id}")
//	@Update("UPDATE user_1 SET name = #{name}, age = #{age} WHERE id = #{id}")
	int updateUser(@Param("user") User1 user);
}
